<?php
namespace app\shadmin\controller;





use think\Db;
use think\Request;

class Login extends \think\Controller
{
    public function index()
    {

     if(IS_AJAX()){

         $s=input("param.");
         if(!$s['user'] || !$s['pwd']){

             $json['code']=400;
             $json['msg']="请输入用户名和密码！";
         }else{

            $where['user']=$s['user'];
            $where['pwd']=md5($s['pwd'].'sohe2017');
            $user=Db::table("sys_admin")->where($where)->find();
            if($user){

                session('aid',$user['id']);
                session('name',$user['name']);
                session('status',$user['status']);
                $json['code']=200;

                  switch($user['status']){

                    case "市场部":
                    $json['url']=url('shadmin/market/index');
                    break;


                    case "运营部":
                     $json['url']=url('shadmin/Sales/index');
                    break;


                    case "财务部":

                    break;


                    case "管理员":
                    $json['url']=url('shadmin/index/index');
                    break;


                  }


               


            }else{

                 $json['code']=400;
                 $json['msg']="用户名或密码错误";

            }

         }

         return json($json);

     }else{
      return view();

     }



    }


    public function out(){

        session(null);
        $this->redirect('shadmin/index/index');


    }

    public function noacc(){

         return view();  
   

    }








}
